const Path = require("path");
const Webpack = require("webpack");
const { merge: WebpackMerge } = require("webpack-merge");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const WebpackConfig = require("./webpack.common.js");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const TerserPlugin = require("terser-webpack-plugin");
const AddAssetHtmlPlugin = require("add-asset-html-webpack-plugin");
const { resolve } = Path;

module.exports = WebpackMerge(WebpackConfig, {
  mode: "production",
  devtool: "hidden-source-map",
  entry: {
    app: resolve(__dirname, "./src/main"),
  },
  optimization: {
    minimize: true,
    minimizer: [
      new TerserPlugin({
        extractComments: false
      })
    ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new Webpack.DllReferencePlugin({
      manifest: require("./library/library.json"),
    }),
    new AddAssetHtmlPlugin({
      outputPath: "js",
      filepath: Path.resolve(__dirname, "./library/library_9e384f16b24851e579d4.dll.js")
    }),
    new BundleAnalyzerPlugin()
  ],
});
